package com.cloud.code.牛客网;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * HJ48 从单向链表中删除指定值的节点
 */
public class Test14 {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String s = scanner.nextLine();
        String[] s1 = s.split(" ");
        List<Integer> list = new ArrayList<>(Integer.parseInt(s1[0]));
        list.add(0,Integer.parseInt(s1[1]));
        int i = 2;
        for (int j = 0; j < Integer.parseInt(s1[0])-1; j++) {
            int i1 = Integer.parseInt(s1[i]);
            int i2 = Integer.parseInt(s1[i + 1]);
            int i3 = list.indexOf(i2);
            list.add(i3+1,i1);
            i+=2;
        }

        Integer delete = Integer.parseInt(s1[s1.length-1]);
        list.remove(delete);

        list.forEach(integer -> {
            System.out.print(integer+" ");
        });
    }
}
